﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Uniforax.Core.Common;

namespace Uniforax.Core.GameActions
{
    public class AddMoneyAction : BaseGameAction
    {
        public int PlayerId { get; set; }

        public int OldMoney { get; set; }

        public int MoneyAmount { get; set; }

        public AddMoneyAction(int playerId, int moneyAmount)
        {
            PlayerId = playerId;
            if (moneyAmount <= 0) throw new InvalidDataException();
            MoneyAmount = moneyAmount;
        }

        public override void Execute(ActionContext context)
        {
            var world = context.GameWorld;
            var playerData = world.GetPlayerData(PlayerId);

            OldMoney = playerData.Money;

            var newMoney = playerData.Money + MoneyAmount;
            playerData.Money = newMoney;
        }

        public override void Undo(ActionContext context)
        {
            var world = context.GameWorld;
            var playerData = world.GetPlayerData(PlayerId);

            playerData.Money = OldMoney ;
        }
    }
}
